/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Component;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.*;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author Phong
 */
public class NhatKyHeThong extends javax.swing.JPanel {

    /**
     * Creates new form NhatKyHeThong
     */
    public void SetIcon(JTable table, int col_index, ImageIcon icon,String name){
		table.getTableHeader().getColumnModel().getColumn(col_index).setHeaderRenderer(new iconRenderer());
		table.getColumnModel().getColumn(col_index).setHeaderValue(new txtIcon(name, icon));
	}
    public class iconRenderer extends DefaultTableCellRenderer{
        public Component getTableCellRendererComponent(JTable table, Object obj,boolean isSelected, boolean hasFocus, int row, int column) {
			txtIcon i = (txtIcon)obj;
            if (obj == i) {
               setIcon(i.imageIcon);
               setText(i.txt);
            }
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            setHorizontalAlignment(JLabel.CENTER);
            return this;
        }
    }
    public class txtIcon {
		String txt;
		ImageIcon imageIcon;
		txtIcon(String text, ImageIcon icon) {
			txt = text;
            imageIcon = icon;
        }
	}
    public NhatKyHeThong() {
        initComponents();
        Vector<String> colName = new Vector<>();
        colName.add("Ngày-Giờ");
        colName.add("Hành Động");
        colName.add("Bảng Dữ Liệu");
        colName.add("Người Dùng");
        colName.add("Nhóm");

        Vector row;
        DefaultTableModel dtm = new DefaultTableModel() {
            @Override
            public boolean isCellEditable(int i, int i1) {
                return false;
            }
        };
        dtm.setColumnIdentifiers(colName);
        BufferedReader reader = null;
        String NgayThang = "";
        String HanhDong = "";
        String Bang = "";
        String Username = "";
        String Group = "";
        try {
            reader = new BufferedReader(new FileReader("NhatKiHeThong.log"));
            String line = null;
            while ((line = reader.readLine()) != null) {
                String[] tmpStr = line.split("@");
                NgayThang = tmpStr[0];
                HanhDong = tmpStr[1];
                Bang = tmpStr[2];
                Username = tmpStr[3];
                Group = tmpStr[4];

                row = new Vector();
                row.add(NgayThang);
                row.add(HanhDong);
                row.add(Bang);
                row.add(Username);
                row.add(Group);
                dtm.addRow(row);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(NhatKyHeThong.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(NhatKyHeThong.class.getName()).log(Level.SEVERE, null, ex);
        }
        jTableNhatKi.setModel(dtm);
        
        
        ImageIcon imageIcon = new ImageIcon("src\\Images\\date.png");
        SetIcon(jTableNhatKi, 0, imageIcon,"Ngày-Giờ");
          imageIcon = new ImageIcon("src\\Images\\HanhDong.png");
        SetIcon(jTableNhatKi, 1, imageIcon,"Hành Động");
          imageIcon = new ImageIcon("src\\Images\\BangDuLieu.png");
        SetIcon(jTableNhatKi, 2, imageIcon,"Bảng Dữ Liệu");
          imageIcon = new ImageIcon("src\\Images\\nguoidung.png");
        SetIcon(jTableNhatKi, 3, imageIcon,"Người Dùng");
          imageIcon = new ImageIcon("src\\Images\\Nhom.png");
        SetIcon(jTableNhatKi, 4, imageIcon,"Nhóm");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableNhatKi = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jButtonXuat = new javax.swing.JButton();
        jButtonIn = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        txtnoiluufile = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cbbxuatra = new javax.swing.JComboBox();
        btnchooser = new javax.swing.JButton();

        jTableNhatKi.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTableNhatKi);

        jButtonXuat.setForeground(new java.awt.Color(255, 51, 51));
        jButtonXuat.setText("Xuất");
        jButtonXuat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonXuatActionPerformed(evt);
            }
        });

        jButtonIn.setForeground(new java.awt.Color(255, 0, 0));
        jButtonIn.setText("In");

        jLabel4.setText("Nơi Lưu File:");

        txtnoiluufile.setText("C:\\\\DanhSachNhanVien.xls");
        txtnoiluufile.setEnabled(false);
        txtnoiluufile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtnoiluufileActionPerformed(evt);
            }
        });

        jLabel3.setText("Xuất Ra:");

        cbbxuatra.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Microsoft Excel", "Microsoft Word" }));
        cbbxuatra.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbbxuatraActionPerformed(evt);
            }
        });

        btnchooser.setText("...");
        btnchooser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnchooserActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonIn, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbbxuatra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtnoiluufile, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnchooser, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonXuat, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(310, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButtonIn, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonXuat, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(cbbxuatra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(txtnoiluufile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnchooser)))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonXuatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonXuatActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_jButtonXuatActionPerformed

    private void cbbxuatraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbbxuatraActionPerformed

    }//GEN-LAST:event_cbbxuatraActionPerformed

    private void txtnoiluufileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtnoiluufileActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtnoiluufileActionPerformed

    private void btnchooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnchooserActionPerformed

    }//GEN-LAST:event_btnchooserActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnchooser;
    private javax.swing.JComboBox cbbxuatra;
    private javax.swing.JButton jButtonIn;
    private javax.swing.JButton jButtonXuat;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableNhatKi;
    private javax.swing.JTextField txtnoiluufile;
    // End of variables declaration//GEN-END:variables
}
